package com.lengmou.service.impl;

import com.lengmou.dao.OrdersInfoDao;
import com.lengmou.entity.OrdersInfo;
import com.lengmou.service.OrdersInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@Service("OrdersInfoService")
public class OrdersInfoServiceImpl implements OrdersInfoService {
    @Resource
    private OrdersInfoDao oid;
    @Override
    public List<OrdersInfo> getAll() {
        return oid.queryAll();
    }

    @Override
    public OrdersInfo getInfoById(String id) {
        return oid.querysById(id);
    }

    @Override
    public List<OrdersInfo> getInfoByOrdersId(int ordersId) {
        return oid.querysByOrdersid(ordersId);
    }

    @Override
    public List<OrdersInfo> search(Map<String, Object> map) {
        return oid.search(map);
    }

    @Override
    public int addOrdersInfo(OrdersInfo info) {
//        给一个id
        info.setId(UUID.randomUUID().toString());

        return oid.addOrdersInfo(info);
    }

    @Override
    public int setInfoGoodsId(OrdersInfo info) {
        OrdersInfo infoById = getInfoById(info.getId());
        if(infoById!=null){
            infoById.setGoodsid(info.getGoodsid());
            return oid.updateOrderInfo(infoById);
        }
        return -1;
    }

    @Override
    public int setInfoOrdersId(OrdersInfo info) {
        OrdersInfo infoById = getInfoById(info.getId());
        if(infoById!=null){
            infoById.setOrdersid(info.getOrdersid());
            return oid.updateOrderInfo(infoById);
        }
        return -1;
    }

    @Override
    public int setInfoNum(OrdersInfo info) {
        OrdersInfo infoById = getInfoById(info.getId());
        if(infoById!=null){
            infoById.setNum(info.getNum());
            return oid.updateOrderInfo(infoById);
        }
        return -1;
    }

    @Override
    public int deleteOrdersInfo(String id) {
        OrdersInfo infoById = getInfoById(id);
        if(infoById!=null){
            return oid.deleteOrderInfo(id);
        }
        return -1;
    }

    @Override
    public int deleteByOrdersid(int ordersid) {
        return oid.deleteByOrdersid(ordersid);
    }
}
